home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / gfa / stik_gfa / stik_gfa.lst < prev    next >
Encoding:
File List  |  1997-06-08  |  4.7 KB  |  149 lines

  1. ' GFA-BAsic Example Code for STiK  v1.08
  2. ' by Lonny Pursell
  3. ' (C)1997 by Lonny Pursell and ENCOM
  4. ' All rigths reserved.
  5. ' Date: 6/8/97
  6. ' E-Mail: atari@bright.net
  7. '
  8. ' ==============================================================================
  9. ' NOTE: This is not meant to be executed and is only an example of STiK access!
  10. ' ==============================================================================
  11. '
  12. $C+ !save/restore registers when using the C:() function
  13. ' ------------------------------------------------------------------------------
  14. ' ** init_stik()
  15. status&=@init_stik !this routine must be called once before any STiK access
  16. SELECT status&
  17. CASE 0
  18.   PRINT "STiK access is granted"
  19. CASE -1
  20.   PRINT "SYSTEM HAS NO COOKIE JAR"
  21. CASE -2
  22.   PRINT "STiK NOT FOUND"
  23. CASE -3
  24.   PRINT "STiK IS DISABLED"
  25. CASE -4
  26.   PRINT "STiK MAGIC NOT FOUND"
  27. CASE -5
  28.   PRINT "TRANSPORT LAYER NOT LOADED"
  29. ENDSELECT
  30. ' ------------------------------------------------------------------------------
  31. ' ** version$()
  32. vn$=@version$
  33. PRINT "STiK version is ";vn$
  34. ' ------------------------------------------------------------------------------
  35. ' ** resolve()
  36. domain$="post.demon.co.uk" !server to fetch ip address of
  37. ip%=0 !this will hold the ip address when resolve() returns
  38. result&=@resolve(domain$,0,V:ip%,1)
  39. IF result&=1 !we got an ip address?
  40.   ' function ip_str$() simply displays the ip% address in dotted decimal
  41.   PRINT "the ip address of ";domain$;" is ";@ip_str$(ip%)
  42. ELSE
  43.   PRINT "resolve() failed"
  44.   PRINT @get_err_text$(result&)
  45. ENDIF
  46. ' ------------------------------------------------------------------------------
  47. ' ** tcp_open()
  48. ch&=@tcp_open(ip%,139,0,1024)
  49. ' ch&=@tcp_open(0,0,0,1024) !this would be a listen socket
  50. IF ch&=>0 !connection opened?
  51.   PRINT "the connection handle returned is ";ch&
  52. ELSE
  53.   PRINT "tcp_open() failed"
  54.   PRINT @get_err_text$(ch&)
  55. ENDIF
  56. ' ------------------------------------------------------------------------------
  57. ' ** cngetinfo()
  58. cib%=@cngetinfo(ch&) !get pointer to structure
  59. IF cib%>0 !valid pointer?
  60.   PRINT "local port is ";CARD{cib%+2}
  61. ELSE
  62.   PRINT "bad connection handle"
  63. ENDIF
  64. ' ------------------------------------------------------------------------------
  65. ' ** tcp_wait_state()
  66. status&=@tcp_wait_state(ch&,4,60) !the 4 means wait for connection established
  67. IF status&<0
  68.   PRINT "tcp_wait_state() failed"
  69.   PRINT @get_err_text$(status&)
  70. ELSE
  71.   PRINT "connection established"
  72. ENDIF
  73. ' ------------------------------------------------------------------------------
  74. ' ** tcp_send()
  75. buf$="Send this line out the connection"
  76. status&=@tcp_send(ch&,V:buf$,LEN(buf$))
  77. IF status&<0
  78.   PRINT "tcp_send() failed"
  79.   PRINT @get_err_text$(status&)
  80. ELSE
  81.   PRINT LEN(buf$);" bytes of data sent on connection ";ch&
  82. ENDIF
  83. ' ------------------------------------------------------------------------------
  84. ' ** cnbyte_count()
  85. count&=@cnbyte_count(ch&)
  86. IF count&<0
  87.   PRINT "error detected"
  88.   PRINT @get_err_text$(count&)
  89. ELSE IF status&=0 !no data?
  90.   PRINT "no data came in yet on connection ";ch&
  91. ELSE IF count&>0 !we got data?
  92.   PRINT count&;" bytes came in on connection ";ch&
  93. ENDIF
  94. ' ------------------------------------------------------------------------------
  95. ' ** cnget_char()
  96. count&=@cnbyte_count(ch&)
  97. IF count&>0
  98.   char&=@cnget_char(ch&)
  99.   IF char&=>0 !we got data?
  100.     PRINT "one byte (";char&;") fetched from connection ";ch&
  101.   ELSE
  102.     PRINT "error detected"
  103.     PRINT @get_err_text$(char&)
  104.   ENDIF
  105. ENDIF
  106. ' ------------------------------------------------------------------------------
  107. ' ** cnget_block()
  108. count&=@cnbyte_count(ch&)
  109. IF count&>0
  110.   buf$=SPACE$(count&) !create a buffer
  111.   status&=@cnget_block(ch&,V:buf$,count&)
  112.   IF status&<0
  113.     PRINT "error detected"
  114.     PRINT @get_err_text$(status&)
  115.   ELSE IF status&>0 !we got data?
  116.     PRINT count&;" bytes fetched from connection ";ch&
  117.   ENDIF
  118. ENDIF
  119. ' ------------------------------------------------------------------------------
  120. ' ** tcp_close()
  121. status&=@tcp_close(ch&,5)
  122. IF status&<0
  123.   PRINT "tcp_close() failed"
  124.   PRINT @get_err_text$(status&)
  125. ELSE
  126.   PRINT "connection closed"
  127. ENDIF
  128. ' ------------------------------------------------------------------------------
  129. ' ** getvstr$()
  130. tag$="ALLOCMEM"
  131. d$=@getvstr$(tag$)
  132. IF LEN(d$)>0
  133.   PRINT "tag ";tag$;" is set to ";d$
  134. ELSE
  135.   PRINT "tag ";tag$;" is not set or missing"
  136. ENDIF
  137. ' ------------------------------------------------------------------------------
  138. ' ** carrier_detect()
  139. cd&=@carrier_detect
  140. IF cd&=-1
  141.   PRINT "carrier not detected"
  142. ELSE IF cd&=0
  143.   PRINT "carrier detect unknown"
  144. ELSE IF cd&=1
  145.   PRINT "carrier is detected"
  146. ENDIF
  147. ' ------------------------------------------------------------------------------
  148. ' eof
  149.